function Q=evaluadorPuntosDeCambio(data,idxUp,idxDown,k1,k1p,k2,k2p,...
                                                    m1,m1p,m2,m2p)
    verbose=1;
    
    apertura=data(:,2);
    high=data(:,3);
    low=data(:,4);
    cierre=data(:,5);
    
    idxUp=cleanSequences(idxUp);
    idxDown=cleanSequences(idxDown);
    idxUpCorrect=[];
    idxUpIncorrect=[];
    for j=1:length(idxUp)
        % Cambios hacia arriba
        i=idxUp(j);
        if cierre(i-2*k1)*(1+2*k2)>=cierre(i) && cierre(i)<=cierre(i+2*k1p)*(1+2*k2p)
            idxUpCorrect=[idxUpCorrect i];
        else
            idxUpIncorrect=[idxUpIncorrect i];
        end
    end
    idxDownCorrect=[];
    idxDownIncorrect=[];
    for j=1:length(idxDown)
        % Cambios hacia arriba
        i=idxDown(j);
        if cierre(i-2*m1)*(1+2*m2)<=cierre(i) && cierre(i)>=cierre(i+2*m1p)*(1+2*m2p)
            idxDownCorrect=[idxDownCorrect i];
        else
            idxDownIncorrect=[idxDownIncorrect i];
        end
    end
    if verbose==1
        N=size(cierre,1);
        plot(1:N,cierre,...
            idxUpCorrect,cierre(idxUpCorrect),'o',...
            idxUpIncorrect,cierre(idxUpIncorrect),'o',...
            idxDownCorrect,cierre(idxDownCorrect),'x',...
            idxDownIncorrect,cierre(idxDownIncorrect),'x')
        disp(num2str([length(idxDownCorrect) length(idxUpCorrect)]));
        disp(num2str([length(idxDownCorrect)/length(idxDown) length(idxUpCorrect)/length(idxUp)]));
    end
    cantidad=0.5*(length(idxUp)+length(idxDown));
    calidad=0.5*(...
            length(idxDownCorrect)/length(idxDown)+...
            length(idxUpCorrect)/length(idxUp));
    Q=cantidad*calidad;
end

function idxClean=cleanSequences(idx)
   idxClean=[];
   left=1;
   N=length(idx);
   while left<N
       right=left+1;
       while idx(right-1)>=(idx(right)-1)
           right=right+1;
           if right>N
               break;
           end
       end
       right=right-1;
       idxClean=[idxClean idx(round(0.5*(left+right)))];
       left=right+1;
   end
end